<?php


namespace Yond\LaravelDomain\Console\Domain;

use Illuminate\Support\Str;
use Yond\LaravelDomain\Console\DomainGenerator;

class MigrationMakeCommand extends DomainGenerator
{

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'yond:domain:migration {--model= : The name of model to make migration}
                                                  {--type= : The type of migration}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Make a domain migration';

    protected $type;

    protected function getUserInputs()
    {
        $model = ucfirst($this->optionOrAsk('model', 'Please enter the name of model to make migration'));
        $this->type = $this->optionOrChoice('type', 'Please choice the type of migration', ['create', 'update'], 0);

        $table = Str::snake($this->domainName . Str::pluralStudly($model));

        if ($this->type === 'update') {
            $prefix = $this->ask('Please enter prefix for update migration class');
        } else {
            $prefix = 'Create';
        }

        $file = Str::snake($prefix . $this->domainName . Str::pluralStudly($model).'Table');

        return [
            'path' => [
                'domain' => $this->domainName,
                'file' => date('Y_m_d_His').'_'.$file,
            ],
            'stub' => [
                'class' => Str::studly($file),
                'table' => $table,
            ],
        ];
    }

    protected function getStubName()
    {
        return 'database/migration.'. $this->type .'.stub';
    }

    protected function getPathStructure()
    {
        return 'domain/{domain}/Database/Migrations/{file}.php';
    }
}
